﻿
$(document).ready(function()
{
    $(".tx").keyup(function() {
        var tmptxt = $(this).val();
        $(this).val(tmptxt.replace(/\D|^0/g, ''));
    }).bind("paste", function() {
        var tmptxt = $(this).val();
        $(this).val(tmptxt.replace(/\D|^0/g, ''));
    }).css("ime-mode", "disabled");

})


function ValidData() {

    var intContactNum = $(".clsContactTable").length;
    $("#" + mstrControlProfix + "hidContactNum").val(intContactNum);

    var lblCompanyCode = document.getElementById(mstrControlProfix + "lblCompanyCode");
    var txtCompanyName = document.getElementById(mstrControlProfix + "txtCompanyName");
    var txtTaxNumber = document.getElementById(mstrControlProfix + "txtTaxNumber");

    var txtEmail = document.getElementById(mstrControlProfix + "txtEmail");
   
    var txtContactEmaila = document.getElementById(mstrControlProfix + "txtContactEmail");
    var txtZipCode = document.getElementById(mstrControlProfix + "txtZipCode"); 


    if (lblCompanyCode.value == "") {
        alert("公司代码不能为空。");
        return false;
    }
    if (txtCompanyName.value == "") {
        alert("公司全称不能为空。");
        txtCompanyName.focus();
        return false;
    }
    if (txtTaxNumber.value == "") {
        alert("税务登记号不能为空。");
        txtTaxNumber.focus();
        return false;
    }


    if (!(/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/.test(txtEmail.value)) && txtEmail.value != "") {
        alert("请输入正确的邮箱格式。例如：<XXXX@XXX.XXX>。");
        txtEmail.focus();
        return false;
    }

    if (!(/^\d{6}$/.test(txtZipCode.value)) && txtZipCode.value != "") {
        alert("请输入正确邮编格式。");
        txtZipCode.focus();
        return false;
    }

    if (!(/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/.test(txtContactEmaila.value)) && txtContactEmaila.value != "") {
        alert("请输入正确的邮箱格式。例如：<XXXX@XXX.XXX>。");
        txtContactEmaila.focus();
        return false;
    }

    if (intContactNum > 1) {

        for (var i = 1; i < intContactNum; i++) {
            var txtContactEmail = document.getElementById("txtContactEmail" + i + "");
            if (!(/[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+$/.test(txtContactEmail.value)) && txtContactEmail.value != "") {
                alert("请输入正确的邮箱格式。例如：<XXXX@XXX.XXX>。");
                txtContactEmail.focus();
                return false;
            }
        }
    }
    return true;
}
